
package com.android.formula.task;

import java.util.ArrayList;

import android.content.Context;

import com.android.formula.common.MyApplication;
import com.android.formula.dao.SubSubjectDao;
import com.android.formula.database.SQLiteTable;
import com.android.formula.model.SubSubject;
import com.android.formula.model.Subject;
import com.android.formula.utils.Constants;

/**
 * Get a Spot by Id
 */
public class GetSubSubjectDBTask extends BaseDatabaseTask<Subject, ArrayList<SubSubject>> {

    public GetSubSubjectDBTask(Context context, Subject param,
            IDataEventHandler<ArrayList<SubSubject>> dataEventHandler) {
        super(context, param, null, dataEventHandler);
    }

    @Override
    protected ArrayList<SubSubject> execute() {
        SQLiteTable sqlt = MyApplication.getSqLiteTable();
        if (sqlt == null || mRequestParams == null) {
            return null;
        }

        sqlt.open();
        SubSubjectDao dao = new SubSubjectDao(SubSubject.class, mContext, sqlt.getDatabase());
        ArrayList<SubSubject> list = dao.getItemsFromId(Constants.TABLE_SUB_SUBJECT_COL_SUBJECTID,
                "" + mRequestParams.getSubjectId());
        sqlt.close();
        if (!list.isEmpty()) {
            return list;
        } else {
            return null;
        }
    }
}
